package dp.mobile.eden;

import dp.mobile.system.SoundManager;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.SeekBar;
import android.widget.ToggleButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.SeekBar.OnSeekBarChangeListener;

public class OptionAct extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.option);
		
		initComp();
		setListener();
	}
	
	private void initComp(){		
		m_BGMVolumeBar	= (SeekBar) findViewById(R.id.bgm_volume_bar);
		m_SFXVolumeBar	= (SeekBar) findViewById(R.id.sfx_volume_bar);
		m_MuteToggleBtn	= (ToggleButton) findViewById(R.id.mute_toggle_btn);
		
		m_CreditsBtn	= (Button) findViewById(R.id.credit_btn);
		
		m_BGMVolumeBar.setProgress((int)(SoundManager.instance(getBaseContext()).getBGMVolume() * 100));
		m_SFXVolumeBar.setProgress((int)(SoundManager.instance(getBaseContext()).getSFXVolume() * 100));
		Log.d("MUTE", "ISMUUUUUUUTE = " + SoundManager.instance(getBaseContext()).isMute());
		m_MuteToggleBtn.setChecked(SoundManager.instance(getBaseContext()).isMute());
	}
	
	private void setListener(){
		m_BGMVolumeBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
			@Override
			public void onStopTrackingTouch(SeekBar seekBar) {
			}
			
			@Override
			public void onStartTrackingTouch(SeekBar seekBar) {
			}
			
			@Override
			public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
				SoundManager.instance(getBaseContext()).setBGMVolume((float)progress/100.0f);
			}
		});
		
		m_SFXVolumeBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
			@Override
			public void onStopTrackingTouch(SeekBar seekBar) {
			}
			
			@Override
			public void onStartTrackingTouch(SeekBar seekBar) {
			}
			
			@Override
			public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
				SoundManager.instance(getBaseContext()).setSFXVolume((float)progress/100.0f);
			}
		});
		
		m_MuteToggleBtn.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				Log.d("CHECKED CHANGE", "isCHEKCEDDDD = " + isChecked);
				SoundManager.instance(getBaseContext()).setMute(isChecked);
			}
		});
		
		m_CreditsBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				startActivity(new Intent(OptionAct.this.getApplicationContext(), CreditsAct.class));
			}
		});
	}
	
	@Override
	protected void onPause() {
		super.onPause();
		SoundManager.instance(getBaseContext()).temporarySetMute(true);
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		SoundManager.instance(getBaseContext()).temporarySetMute(false);
	}
	
	//ATTRIBUTES
	private SeekBar			m_BGMVolumeBar, m_SFXVolumeBar;
	private ToggleButton	m_MuteToggleBtn;
	private Button			m_CreditsBtn;
}
